package com.csit.util;

import java.util.List;

import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;

/**
 * 
 * @Description:操作Excel的工具类
 * @Copyright: 福州骏华信息有限公司 (c)2012
 * @Created Date : 2012-8-3
 * @author longweier
 * @vesion 1.0
 */
public class ExcelUtil {
	
	/**
	 * 
	 * @Description: 从Excel单元格里面获取内容
	 * @param
	 * @Create: 2012-8-3 上午10:39:20
	 * @author longweier
	 * @update logs
	 * @param sheet
	 * @param column
	 * @param row
	 * @return
	 * @return
	 * @throws Exception
	 */
	public static String getContent(Sheet sheet, int column, int row){
		
		Cell cell = sheet.getCell(column, row);
		
		if(cell.getContents()==null || cell.getType() == CellType.EMPTY || "".equals(cell.getContents().toString().trim())){
			return null;
		}
		
		return cell.getContents().toString().trim();
	}
	/**
	 * 
	 * @Description: 检查excel的模板
	 * @param
	 * @Create: 2012-8-3 上午10:33:35
	 * @author longweier
	 * @update logs
	 * @param s
	 * @param titleList
	 * @return
	 * @return
	 * @throws Exception
	 */
	public static boolean checkTemplate(Sheet sheet, List<String> titleList){
		int columns = sheet.getColumns();
		
		if(columns!=titleList.size()){
			return false;
		}
		Cell cell = null;
		boolean isTrue = false;
		for(int j = 0; j < titleList.size(); j++){
			cell = sheet.getCell(j, 0);
			if(null != cell.getContents() && cell.getType() != CellType.EMPTY && cell.getContents().toString().equals(titleList.get(j).toString())){
				isTrue = true;
			} else {
				isTrue = false;
				break;
			}
		}
		return isTrue;
	}
}
